home *** CD-ROM | disk | FTP | other *** search
/ Motor Sport Digital Archive Collection 1960s / Motor Sport Digital Archive Collection 1960s.iso / main.swf / scripts / mx / binding / Watcher.as < prev   
Encoding:
Text File  |  2008-05-21  |  4.1 KB  |  171 lines

  1. package mx.binding
  2. {
  3.    import mx.collections.errors.ItemPendingError;
  4.    import mx.core.mx_internal;
  5.    
  6.    use namespace mx_internal;
  7.    
  8.    public class Watcher
  9.    {
  10.       mx_internal static const VERSION:String = "2.0.1.0";
  11.       
  12.       private var listeners:Array;
  13.       
  14.       public var value:Object;
  15.       
  16.       protected var cloneIndex:int;
  17.       
  18.       protected var children:Array;
  19.       
  20.       public function Watcher()
  21.       {
  22.          listeners = [];
  23.          super();
  24.       }
  25.       
  26.       public function removeChildren(param1:int) : void
  27.       {
  28.          children.splice(param1);
  29.       }
  30.       
  31.       public function updateChildren() : void
  32.       {
  33.          var _loc1_:int = 0;
  34.          var _loc2_:int = 0;
  35.          if(children)
  36.          {
  37.             _loc1_ = int(children.length);
  38.             _loc2_ = 0;
  39.             while(_loc2_ < _loc1_)
  40.             {
  41.                children[_loc2_].updateParent(this);
  42.                _loc2_++;
  43.             }
  44.          }
  45.       }
  46.       
  47.       protected function shallowClone() : Watcher
  48.       {
  49.          return new Watcher();
  50.       }
  51.       
  52.       protected function wrapUpdate(param1:Function) : void
  53.       {
  54.          var wrappedFunction:Function = param1;
  55.          try
  56.          {
  57.             wrappedFunction.apply(this);
  58.          }
  59.          catch(itemPendingError:ItemPendingError)
  60.          {
  61.             value = null;
  62.          }
  63.          catch(rangeError:RangeError)
  64.          {
  65.             value = null;
  66.          }
  67.          catch(error:Error)
  68.          {
  69.             if(error.errorID != 1006 && error.errorID != 1009 && error.errorID != 1010 && error.errorID != 1055 && error.errorID != 1069)
  70.             {
  71.                throw error;
  72.             }
  73.          }
  74.       }
  75.       
  76.       private function valueChanged(param1:Object) : Boolean
  77.       {
  78.          var _loc2_:* = null;
  79.          if(param1 == null && value == null)
  80.          {
  81.             return false;
  82.          }
  83.          _loc2_ = typeof value;
  84.          if(_loc2_ == "string")
  85.          {
  86.             if(param1 == null && value == "")
  87.             {
  88.                return false;
  89.             }
  90.             return param1 != value;
  91.          }
  92.          if(_loc2_ == "number")
  93.          {
  94.             if(param1 == null && value == 0)
  95.             {
  96.                return false;
  97.             }
  98.             return param1 != value;
  99.          }
  100.          if(_loc2_ == "boolean")
  101.          {
  102.             if(param1 == null && value == false)
  103.             {
  104.                return false;
  105.             }
  106.             return param1 != value;
  107.          }
  108.          return true;
  109.       }
  110.       
  111.       public function notifyListeners(param1:Boolean) : void
  112.       {
  113.          var _loc2_:int = 0;
  114.          var _loc3_:int = 0;
  115.          _loc2_ = int(listeners.length);
  116.          _loc3_ = 0;
  117.          while(_loc3_ < _loc2_)
  118.          {
  119.             listeners[_loc3_].watcherFired(param1,cloneIndex);
  120.             _loc3_++;
  121.          }
  122.       }
  123.       
  124.       protected function deepClone(param1:int) : Watcher
  125.       {
  126.          var _loc2_:Watcher = null;
  127.          var _loc3_:int = 0;
  128.          var _loc4_:int = 0;
  129.          var _loc5_:Watcher = null;
  130.          _loc2_ = shallowClone();
  131.          _loc2_.cloneIndex = param1;
  132.          _loc2_.listeners = listeners.concat();
  133.          if(children)
  134.          {
  135.             _loc3_ = int(children.length);
  136.             _loc4_ = 0;
  137.             while(_loc4_ < _loc3_)
  138.             {
  139.                _loc5_ = children[_loc4_].deepClone(param1);
  140.                _loc2_.addChild(_loc5_);
  141.                _loc4_++;
  142.             }
  143.          }
  144.          return _loc2_;
  145.       }
  146.       
  147.       public function updateParent(param1:Object) : void
  148.       {
  149.       }
  150.       
  151.       public function addChild(param1:Watcher) : void
  152.       {
  153.          if(!children)
  154.          {
  155.             children = [param1];
  156.          }
  157.          else
  158.          {
  159.             children.push(param1);
  160.          }
  161.          param1.updateParent(this);
  162.       }
  163.       
  164.       public function addListener(param1:Binding) : void
  165.       {
  166.          listeners.push(param1);
  167.       }
  168.    }
  169. }
  170.  
  171.